﻿
$(document).ready(function() {
    var houseManage = new Chenxin.UI.HouseManage({
        createGrid: function() {
            var _this = this;
            return new Chenxin.UI.ExpandGrid({
                actionUrl: '/service/housemgrnew1.ashx?op=getlist',
                id: 'houselist',
                autoLoad: false,
                hasRowNumber: false,
                height: 300,
                renderTo: 'house_table',
                hasCheckBox: false,                
                afterRenderTitleTool: function() {
                    var _obj = this;
                    this.sortCombo = new Chenxin.UI.Combo({
                        containerId: '#xyz',
                        name: 'sortField',
                        defVal: '',
                        defTxt: '默认排序',
                        colNum: 1,
                        colWidth: 105,
                        items: [
							{ txt: '按跟盘时间升序', val: 'servicetime asc', icon: 'x-sort-asc' },
							{ txt: '按跟盘时间降序', val: 'servicetime desc', icon: 'x-sort-desc' },
							{ txt: '按建档时间升序', val: 'adddate asc', icon: 'x-sort-asc' },
							{ txt: '按建档时间降序', val: 'adddate desc', icon: 'x-sort-desc' }
						],
                        onSelected: function() {
                            _obj.sortField = this.getValue();
                            _obj.reload();
                        },
                        afterHeadSelect: function(el) {
                            if (el.f) {
                                this.sortCombo.setVal(this.sortDir.field.toLowerCase() + ' ' + this.sortDir.dir);
                            }
                        }
                    });
                },
                createTitleTool: function() {
                    return [{
                        text: '<div style="float:left;">排序：</div><div class="SelectWrapSingle" id="xyz" style="z-index:1; margin-top:2px;"></xyz>',
                        showTitle: false
}];
                    },
                    afterHeadSelect: function(el) {
                        var _sf = this.sortDir.field.toLowerCase() + ' ' + this.sortDir.dir;
                        if (this.sortCombo.findTxtByVal(_sf)) {
                            this.sortCombo.setValue(_sf);
                        } else {
                            this.sortCombo.reset();
                        }
                    },
                    scope: this,
                    rowExpandAble: true,
                    rowExpand: function(dom, el, grid) {
                        _this.loadHouseInfo();
                    }
                });
            },

            renderHouseInfo: function() {
                var m = this.currentHouseInfo;
                var infoStr = '';
                //infoStr += '<d id="tr-house-info" style="height:100px;"><td colspan="11" class="gendan_box" >';
                infoStr += '<div class="houtab fl">';
                infoStr += '<ul class="padding5">';
                infoStr += '<li style="float:left;width:360px;"><b>' + m.Community;
                switch (m.BusinessKind) {
                    case 10: //出售
                        var p = (m.SalePrice_T / 10000);

                        infoStr += '&nbsp;&nbsp;<span class="red20">售价：' + p.toFixed(0) + '万</span>';
                        break;
                    case 20: //出租
                        infoStr += '&nbsp;&nbsp;<span class="red20">租价：' + m.RentPrice + '元</span>';
                        break;
                    case 30: //租售
                        var p = (m.SalePrice_T / 10000);

                        infoStr += '&nbsp;&nbsp;<span class="red20">售价：' + p.toFixed(0) + '万</span>';
                        infoStr += '&nbsp;&nbsp;<span class="red20">租价：' + m.RentPrice + '元</span>';
                        break;
                }

                infoStr += '</b></li>';
                infoStr += '<li style="float:left;width:360px;">地址：' + m.Address + ' ' + ' ' + m.BuildingName + ' ' + m.Room + '</li>';
                infoStr += '<li style="float:left;width:230px;">编号：' + m.HouseCode + '</li>';
                // infoStr += '<li style="float:left;width:110px;">单价：' + Math.round(m.SalePrice_T / m.BuildingArea) + '</li>';
                if (m.BusinessKind != 20) {
                    infoStr += '<li style="float:left;width:110px;">单价：' + (m.SalePrice_T / m.BuildingArea).toFixed(0) + '元</li>';
                }
                infoStr += '<li style="float:left;width:230px;">板块：' + m.Block + '</li>';
                infoStr += '<li style="float:left;width:100px;">类型：' + m.BuildingType + '</li>';
                infoStr += '<li style="float:left;width:230px;">建档日期：' + m.Adddate + '</li>';
                infoStr += '<li style="float:left;width:100px;">装修：' + m.Fitment + '</li>';
                infoStr += '<li style="float:left;width:360px;">';
                infoStr += '<div class="btn_pon_3"><a href="ShowDetailInfo.aspx?houseid=' + m.HouseId + '" target="_blank" title="查看详情" >查看详情</a></div>'
                infoStr += '<input name="btn_viewownerinfo" type="button" class="btn_pon_2" value="查看业主信息"/>';
                infoStr += '<input name="btn_trace" type="button" class="btn_pon" value="我要跟单"/>';
                infoStr += '<input name="btn_houseSend" type="button" class="btn_pon" value="房源推送"/>';
                infoStr += '</li>';
                infoStr += '</ul>';
                infoStr += '</div>';
                infoStr += '<div class="gdtab"><div>';
                //infoStr += '<div class="infos intitss"><span class="rb"><b>跟单内容</b></span><span class="rbpsn"><b>跟单人</b></span><span class="rbtim"><b>跟单时间</b></span></div>';
                infoStr += '<div id="housetrace_table" style="height:120px;"></div>';
                infoStr += '</div></div>'; //<div id="housetrace_page"></div>
                $('#exp_' + this.currentId).find('dd').append(infoStr);
            },
            createTraceList: function(count) {
                if (!this.tracePage) {
                    this.tracePage = new Chenxin.UI.Pagination({
                        id: 'housetrace',
                        renderTo: 'housetrace_table',
                        pageSize: 20,
                        actionUrl: '/service/housemgrnew1.ashx?op=gethousetracelist',
                        data: { houseid: this.currentId }
                    });
                } else {
                    this.tracePage.recordCount = 0;
                    this.tracePage.hasCount = false;
                    this.tracePage.reload({ houseid: this.currentId });
                }
            }
        });
    });